package com.javapub.flowable.myflowable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.flowable.cmmn.engine.impl.process.ProcessInstanceService;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import liquibase.pro.packaged.A;

@SpringBootTest
public class ExpenseApply {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;


    @Autowired
    private HistoryService historyService;

    @Test
    void flowPhoto(){
        Deployment deploy = repositoryService.createDeployment().addClasspathResource("processes/ExpenseApply.xml").deploy();
        System.out.println("输出deploy"+deploy);
        System.out.println("输出信息");
    }

    /**
     * 启动一个流程的方式
     */
    @Test
    void startProcessId(){
       Map<String,Object> map = new HashMap<>();
       map.put("taskUser", "弄这");
       ProcessInstance startProcessInstanceById = runtimeService.startProcessInstanceById("Expense:13:30004",map);
       System.out.println("启动成功"+startProcessInstanceById);
    }

    @Test
    void queryTask(){
        List<Task> list = taskService.createTaskQuery().list();
        list.forEach(s -> System.out.println(s));
    }

    /**
     * 完成任务
     */
    @Test
    void completeTask(){
        Map<String,Object> map = new HashMap<>();
        map.put("money",7000);
        taskService.complete("57506",map);
        System.out.println("完成任务");
    }

    @Test
    void historyTask(){
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().list();
        list.forEach(s -> System.out.println(s.toString()));
        
    }
}
